//
//  YUNNavControl.m
//  BuDeJie
//
//  Created by warm on 17/8/12.
//  Copyright © 2017年 小码哥. All rights reserved.
//

#import "YUNNavControl.h"

@interface YUNNavControl ()<UIGestureRecognizerDelegate>

@end

@implementation YUNNavControl

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
    
    [self.view addGestureRecognizer:pan];
    
    // 控制手势什么时候触发,只有非根控制器才需要触发手势
    pan.delegate = self;
    
    // 禁止之前手势
    self.interactivePopGestureRecognizer.enabled = NO;
    
    // 假死状态:程序还在运行,但是界面死了.
    
    /*
     为什么导航控制器的手势不是全屏滑动 =>
     */

    
    
    
}


+(void)load
{

    UINavigationBar *navBar=[UINavigationBar appearanceWhenContainedIn:self, nil];

    NSMutableDictionary *attrs=[NSMutableDictionary dictionary];
    
    attrs[NSFontAttributeName]=[UIFont boldSystemFontOfSize:20];
    [navBar setTitleTextAttributes:attrs];
    [navBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];

}



- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return self.childViewControllers.count > 1;
}




- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count > 0) { // 非根控制器
        
        
        
        //当push的时候讲底部的条隐藏掉
        viewController.hidesBottomBarWhenPushed=YES;
        
        // 恢复滑动返回功能 -> 分析:把系统的返回按钮覆盖 -> 1.手势失效(1.手势被清空 2.可能手势代理做了一些事情,导致手势失效)
        
        // 设置返回按钮,只有非根控制器
    
        
        viewController.navigationItem.leftBarButtonItem=[UIBarButtonItem itemWithimage:[UIImage imageNamed:@"navigationButtonReturn"] highImage:[UIImage imageNamed:@"navigationButtonReturnClick"] target:self action:@selector(back) ];
    
    }
    
    // 真正在跳转
    [super pushViewController:viewController animated:animated];
    
}

- (void)back
{
    [self popViewControllerAnimated:YES];
}





@end
